<template>
  <div class="box">
    <div class="loginBox">
      <div class="headImage">
        <span class="title"><h3>登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</h3></span>
      </div>
      <div class="login">
        <div class="innerBox">
          <span class="name">用户名</span>
          <el-input type="text" placeholder="请输入用户名" v-model="loginMessage.username"/>
        </div>
        <div class="innerBox">
          <span class="name">密&nbsp;&nbsp;&nbsp;码</span>
          <el-input type="password" placeholder="请输入密码" v-model="loginMessage.password"/>
        </div>
        <el-button @click="toLogin">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from "vue";
import {Action, ElMessage, ElMessageBox} from "element-plus";
import {useRouter} from "vue-router";
import debounce from 'lodash/debounce'

const router = useRouter();

// 登录信息
const loginMessage = ref({
  username: '',
  password: '',
});

// 点击登录
const toLogin = debounce(() => {
  if(loginMessage.value.username == "" || loginMessage.value.password == "") {
    ElMessageBox.alert('用户名或密码不得为空！','操作失败',{
      confirmButtonText: '确认',
      callback: (action: Action) => {
        ElMessage({
          type: 'error',
          message: '操作失败',
        })
      }
    });
  } else if(loginMessage.value.username != "13875970829" || loginMessage.value.password != "bbx19920506") {
    ElMessageBox.alert('用户名或密码错误！','操作失败',{
      confirmButtonText: '确认',
      callback: (action: Action) => {
        ElMessage({
          type: 'error',
          message: '操作失败',
        })
      }
    });
  } else {
    localStorage.setItem("admin",JSON.stringify(loginMessage.value));
    router.push('/adminMain');
    ElMessage({
      message: '登陆成功！',
      type: 'success'
    });
  }
}, 500);
</script>

<style scoped>
.box {
  margin: 0;
  padding: 0;
  height: 100vh;
  background-color: rgb(235,238,239);
  display: flex;
  justify-content: center;
  align-items: center;
}
.loginBox {
  width: 450px;
  height: 350px;
  border: 1px solid rgb(235,238,239);
  border-radius: 10px;
  box-shadow: 5px 5px 20px gainsboro;
}
.headImage {
  background-image: url("src/assets/images/登录背景1.jpg");
  background-size: 100% 100%;
  height: 130px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-top-right-radius: 10px;
  border-top-left-radius: 10px;
}
h3 {
  color: white;
}
.login {
  background-color: white;
  height: 220px;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  padding-top: 20px;
}
.innerBox {
  padding-top: 20px;
  padding-left: 50px;
}
.el-input {
  width: 260px;
}
.name {
  margin-right: 30px;
}
.el-button {
  margin-top: 30px;
  margin-left: 150px;
  width: 150px;
  background-color: rgb(236,47,27);
  color: white;
}
.el-button:hover {
  background-color: rgb(245,108,108);
}
</style>